import { IClean } from "../../../../com/gengine/core/IClean";
import { EArenaMode } from "../../../../Message/Public/EArenaMode";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PageData } from "./ArenaData/PageData";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ToolTipItem } from "../../../../com/mui/manager/ToolTipItem";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { MsgManager } from "../../manager/MsgManager";
import { SArenaMode } from "../../../../Message/Public/SArenaMode";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { JoinData } from "./ArenaData/JoinData";
import { TitleItem } from "../common/item/TitleItem";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { TilePanel } from "../equipment/TilePanel";
import { ArenaTopCellRenderer } from "./cellRendener/ArenaTopCellRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { MyArenaInfo } from "./ArenaData/MyArenaInfo";
import { SArenaWaitingNum } from "../../../../Message/Public/SArenaWaitingNum";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class ArenaMainPanel
    
    export  class ArenaMainPanel /* flash.display.Sprite */ implements IClean
    {
        constructor()
        {
            
            this._glowYellow = new Object /* flash.filters.GlowFilter */(16776960, 1, 3, 3, 5);
            this._currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
            this._canSelectMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this.createLeftPart();
            this.createRightPart();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            this.updateMyArenaMoney(Cache.instance.role.money.arena);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            if (Cache.instance.arena.arenaMode) 
            {
                this.canSelectMode = Cache.instance.arena.arenaMode;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaGetMyArenaInfo));
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaRefreshTopList, new PageData(this.pageSize, this._pageSelecter.currentPage)));
            return;
        }

        public updateMyArenaMoney(arg1: int): void
        {
            this._tfMyArena.text = Language.getStringByParam(42222, arg1.toString());
            return;
        }

        /* internal  */createLeftPart(): void
        {
            var loc1=null;
            loc1 = new Object /* flash.display.Sprite */();
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createBg(0, 0, 184, 400, loc1);
            this._tfName = this.createItemValue(Language.getString(42214), "0", 12, 5, 150, 20, loc1);
            this._tfScore = this.createItemValue(Language.getString(42215), "0", 12, 24, 90, 20, loc1);
            this._tfRank = this.createItemValue(Language.getString(42216), "0", 104, 24, 90, 20, loc1);
            this._tfWin = this.createItemValue(Language.getString(42217), "0", 12, 43, 90, 20, loc1);
            this._tfLose = this.createItemValue(Language.getString(42218), "0", 104, 43, 90, 20, loc1);
            this._tfTotal = this.createItemValue(Language.getString(42219), "0", 12, 62, 90, 20, loc1);
            this._tfWinPer = this.createItemValue(Language.getString(42220), "100%", 104, 62, 90, 20, loc1);
            this._tfBattleNum = this.createItemValue(Language.getString(42252), "0", 12, 81, 150, 20, loc1);
            this._btnJoin = ObjCreate.createGLoadedButton(ResFileConst.ArenaJoin, 42, 100, 102, 99, loc1);
            this._btnJoin.enabled = true;
            var loc2=new GTextFormat(FontUtil.songtiName, 14, 15859633);
            this._tfWait = ObjCreate.createTextField(Language.getStringByParam(42221, "0"), 20, 205, 160, 20, loc1, loc2);
            this._btnNormalMode = ObjCreate.createGButton(Language.getString(42267), 15, 227, 70, 26, loc1, "Button");
            this._btnMultiMode = ObjCreate.createGButton(Language.getString(42268), 100, 227, 70, 26, loc1, "Button");
            this._multiItem = new ToolTipItem();
            this._multiItem.graphics.beginFill(16777215, 0.01);
            this._multiItem.graphics.drawRect(0, 0, 70, 26);
            this._multiItem.cacheAsBitmap = true;
            ObjCreate.setObjAttri(this._multiItem, 100, 227, 70, 26, loc1);
            this._multiItem.visible = false;
            var loc3=ResouceConst.getScaleBitmap("SplitLine");
            ObjCreate.setObjAttri(loc3, 10, 260, 165, 2, loc1);
            loc1.addChild(loc3);
            this._btnJoin.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnJoin);
            this._spLeftBottom = new Object /* flash.display.Sprite */();
            this._spLeftBottom.x = 10;
            this._spLeftBottom.y = 270;
            loc1.addChild(this._spLeftBottom);
            var loc4=new GTextFormat(FontUtil.songtiName, 15, 15788607);
            var loc5;
            (loc5 = new GTextFormat(FontUtil.songtiName, 13, 15788607)).leading = 4;
            this._tfMyArena = ObjCreate.createTextField(Language.getStringByParam(42222, "0"), 5, 5, 160, 20, this._spLeftBottom, loc4);
            this._tfLastWeekArena = ObjCreate.createTextField(Language.getStringByParam(42223, "0"), 5, 30, 220, 20, this._spLeftBottom, GlobalStyle.textFormat1);
            this._groupTips = ObjCreate.createTextField(Language.getString(42224), 5, 60, 155, 60, this._spLeftBottom, loc5);
            this._groupTips.multiline = true;
            this._groupTips.wordWrap = true;
            this._btnNormalMode.addEventListener(flash.events.MouseEvent.CLICK, this.onChangeMode);
            this._btnMultiMode.addEventListener(flash.events.MouseEvent.CLICK, this.onChangeMode);
            this.updateModeBtnState();
            return;
        }

        /* internal  */onChangeMode(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isCanChangeMode) 
            {
                if (arg1.currentTarget != this._btnNormalMode) 
                {
                    if (this._currentMode.value() != EArenaMode._EArenaOneVsThree) 
                    {
                        this.currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsThree);
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(42270));
                    }
                }
                else if (this._currentMode.value() != EArenaMode._EArenaOneVsOne) 
                {
                    this.currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(42269));
                }
            }
            return;
        }

        public set currentMode(arg1: EArenaMode)
        {
            this._currentMode = arg1;
            this.updateModeBtnState();
            return;
        }

        public set canSelectMode(arg1: SArenaMode)
        {
            this._canSelectMode = arg1.mode;
            this._isInCd = arg1.inCd;
            if (this._canSelectMode.value() == EArenaMode._EArenaOneVsThree && this._isInCd) 
            {
                this._currentMode = EArenaMode.convert(EArenaMode._EArenaOneVsOne);
            }
            this.updateModeBtnState();
            return;
        }

        /* internal  */updateModeBtnState(): void
        {
            this._btnMultiMode.label = Language.getString(42268);
            if (this._currentMode.value() == EArenaMode._EArenaOneVsOne) 
            {
                this._btnNormalMode.enabled = true;
                this._btnNormalMode.filters = [this._glowYellow];
                this._btnMultiMode.filters = [];
                if (this._canSelectMode.value() != EArenaMode._EArenaOneVsThree) 
                {
                    this._btnMultiMode.enabled = false;
                    this._multiItem.toolTipData = this.getMultiTooltipData(false, false);
                    this._multiItem.visible = true;
                }
                else if (this._isInCd) 
                {
                    this._btnMultiMode.enabled = false;
                    this._btnMultiMode.label = Language.getString(42282);
                    this._multiItem.toolTipData = Language.getString(42283);
                    this._multiItem.visible = true;
                }
                else 
                {
                    this._btnMultiMode.enabled = true;
                    this._btnMultiMode.toolTipData = this.getMultiTooltipData(false, true);
                    this._multiItem.visible = false;
                }
                this._btnNormalMode.toolTipData = this.getNormalTooltipData(true);
            }
            if (this._currentMode.value() == EArenaMode._EArenaOneVsThree) 
            {
                this._btnMultiMode.enabled = true;
                this._btnMultiMode.filters = [this._glowYellow];
                this._btnNormalMode.filters = [];
                this._btnNormalMode.enabled = true;
                this._btnMultiMode.toolTipData = this.getMultiTooltipData(true, true);
                this._multiItem.visible = false;
                this._btnNormalMode.toolTipData = this.getNormalTooltipData(false);
            }
            return;
        }

        /* internal  */getNormalTooltipData(arg1: Boolean=true): string
        {
            var loc1="";
            loc1 = Language.getString(42271);
            if (arg1) 
            {
                loc1 = loc1 + Language.getString(42272);
            }
            else 
            {
                loc1 = loc1 + Language.getString(42273);
            }
            loc1 = loc1 + Language.getString(42274);
            return loc1;
        }

        /* internal  */getMultiTooltipData(arg1: Boolean=false, arg2: Boolean=false): string
        {
            var loc1="";
            loc1 = Language.getString(42275);
            if (arg1) 
            {
                loc1 = loc1 + Language.getString(42276);
            }
            else if (arg2) 
            {
                loc1 = loc1 + Language.getString(42277);
            }
            else 
            {
                loc1 = loc1 + Language.getString(42278);
            }
            loc1 = loc1 + Language.getString(42279);
            if (!arg1 && !arg2) 
            {
                loc1 = loc1 + Language.getString(42280);
                loc1 = loc1 + Language.getString(42281);
            }
            return loc1;
        }

        /* internal  */createItemValue(arg1: string, arg2: string="", arg3: number=0, arg4: number=0, arg5: number=90, arg6: number=20, arg7: Object /* flash.display.DisplayObjectContainer */=null): Object /* flash.text.TextField */
        {
            var loc1=ObjCreate.createTextField("", arg3, arg4, arg5, arg6, arg7);
            this.updateItemValue(loc1, arg1, arg2);
            return loc1;
        }

        /* internal  */updateItemValue(arg1: Object /* flash.text.TextField */, arg2: string, arg3: string): void
        {
            arg1.htmlText = HTMLUtil.addColor(arg2, "#FFFFFF") + HTMLUtil.addColor(arg3, GlobalStyle.color1);
            return;
        }

        /* internal  */onBtnJoin(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (this._btnJoin.styleName != ResFileConst.ArenaJoin) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            var loc2=new JoinData(loc1, this._currentMode);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaJoin, loc2));
            return;
        }

        /* internal  */createRightPart(): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            loc1.x = 186;
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createBg(0, 0, 395, 400, loc1);
            var loc2=new Vector.<TitleItem>();
            loc2.push(new TitleItem(Language.getString(42225), 60));
            loc2.push(new TitleItem(Language.getString(42226), 90));
            loc2.push(new TitleItem(Language.getString(42227), 60));
            loc2.push(new TitleItem(Language.getString(42228), 60));
            loc2.push(new TitleItem(Language.getString(42229), 60));
            loc2.push(new TitleItem(Language.getString(42230), 60));
            var loc3=ObjTeamCreate.createTitles(loc2);
            ObjCreate.setObjAttri(loc3, 0, 7, -1, -1, loc1);
            this._arenaTopListPanel = new TilePanel();
            this._arenaTopListPanel.setSize(390, 340);
            this._arenaTopListPanel.rowHeight = 34;
            this._arenaTopListPanel.columnWidth = 390;
            this._arenaTopListPanel.setStyle("cellRenderer", ArenaTopCellRenderer);
            this._arenaTopListPanel.x = 0;
            this._arenaTopListPanel.y = 30;
            loc1.addChild(this._arenaTopListPanel);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.x = 142;
            this._pageSelecter.y = 374;
            loc1.addChild(this._pageSelecter);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onChange);
            this._btnMyPos = ObjCreate.createGButton(Language.getString(42352), 326, 373, 70, 22, loc1, "LinkButton");
            this._btnMyPos.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMyPos);
            return;
        }

        /* internal  */onClickMyPos(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=new PageData(this.pageSize);
            loc1.showMyPos = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaRefreshTopList, loc1));
            return;
        }

        /* internal  */onChange(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaRefreshTopList, new PageData(this.pageSize, this._pageSelecter.currentPage)));
            return;
        }

        public resetOpenState(arg1: Boolean): void
        {
            return;
        }

        public updateMyArenaInfo(arg1: MyArenaInfo): void
        {
            this.updateItemValue(this._tfName, Language.getString(42214), arg1.name);
            this.updateItemValue(this._tfScore, Language.getString(42215), arg1.mark.toString());
            var loc1=Language.getString(42231);
            if (arg1.rank != 0) 
            {
                loc1 = arg1.rank.toString();
            }
            this.updateItemValue(this._tfWin, Language.getString(42217), arg1.winNum.toString());
            this.updateItemValue(this._tfLose, Language.getString(42218), arg1.loseNum.toString());
            this.updateItemValue(this._tfTotal, Language.getString(42219), arg1.totleNum.toString());
            this.updateItemValue(this._tfWinPer, Language.getString(42220), arg1.winPer.toString() + "%");
            this.updateItemValue(this._tfBattleNum, Language.getString(42252), arg1.battleNum.toString());
            this._tfLastWeekArena.text = Language.getStringByParam(42223, arg1.lastArenaMoney.toString());
            return;
        }

        public updateWaitingNum(arg1: SArenaWaitingNum): void
        {
            this._tfWait.htmlText = Language.getStringByParam(42221, arg1.num.toString());
            var loc1=Language.getString(42231);
            if (arg1.rank != 0) 
            {
                loc1 = arg1.rank.toString();
            }
            this.updateItemValue(this._tfRank, Language.getString(42216), loc1);
            return;
        }

        public updateSignUpState(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._btnJoin.styleName = ResFileConst.ArenaCancelJoin;
                this._isCanChangeMode = false;
            }
            else 
            {
                this._btnJoin.styleName = ResFileConst.ArenaJoin;
                this._isCanChangeMode = true;
            }
            return;
        }

        public updateArenaTopData(arg1: Array<any>, arg2: int): void
        {
            this._topList = arg1;
            this._pageSelecter.maxPage = arg2;
            this.updateList();
            return;
        }

        /* internal  */updateList(): void
        {
            this._arenaTopListPanel.dataProvider = this.getDataProvider();
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            return new DataProvider(this._topList);
        }

        public clean(): void
        {
            return;
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_tfWin: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_isCanChangeMode: Boolean=true;

        /* internal */ /* var */_currentMode: EArenaMode;

        /* internal */ /* var */_canSelectMode: EArenaMode;

        /* internal */ /* var */_isInCd: Boolean=false;

        /* internal */ /* var */_glowYellow: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLose: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTotal: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWinPer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfBattleNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnJoin: GLoadedButton;

        /* internal */ /* var */_tfWait: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnNormalMode: GButton;

        /* internal */ /* var */_btnMultiMode: GButton;

        /* internal */ /* var */_multiItem: ToolTipItem;

        /* internal */ /* var */_tfTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_spLeftBottom: Object /* flash.display.Sprite */;

        /* internal */ /* var */_groupTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMyArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLastWeekArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_arenaTopListPanel: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_btnMyPos: GButton;

        /* internal */ /* var */_topList: Array<any>;
    }
